package com.cs171.market.mapper;
import com.cs171.market.entity.User;
import com.cs171.market.entity.UserTable;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import io.lettuce.core.dynamic.annotation.Param;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * @author Endy
 * @create 2020 - 05 - 21 - 22:37
 * @date 2020/5/21 - 22:37
 */

@Mapper
public interface UserMapper {

    @Select("Select u.uid, u.uphone, u.uemail, u.urid FROM user u WHERE u.uid=#{id}")
    UserTable getUserById(Integer id);

    @Select("Update user u SET u.uemail=#{new_email}, u.uphone=#{new_phone} WHERE u.uid=#{id}")
    void updateUserById(Integer id, String new_email,String new_phone);

    @Select("Update user u SET u.ustate=#{new_state} WHERE u.uid=#{id}")
    void updateStateById(Integer id,Integer new_state);

    @Select("Select u.uid, u.uname, u.uphone, u.uemail, u.urid, u.ustate FROM user u WHERE u.uid=#{id}")
    UserTable response_updateState(Integer id);

    @Select("Delete FROM user WHERE uid=#{id}")
    void deleteById(Integer id);

    @Select("Update user SET urid=#{rid} WHERE uid=#{id}")
    void changeRoleById(Integer id, Integer rid);

    @Select("Select uid, uphone, uemail, urid FROM user WHERE uid=#{id}")
    UserTable response_changeRole(Integer id);

    @Select("Select uid, uname, urid, uphone, uemail FROM user WHERE uid=#{id}")
    User userLoginByName(Integer id);

    @Select("Select u.uid, u.uname, u.uphone, u.uemail, u.uaddress, r.role, u.usex, u.ucreate_time, " +
            "u.ustate FROM user u, user_role r WHERE u.urid=r.rid")
    Page<UserTable> new_getUserList();

    @Select("Select COUNT(*) FROM user")
    Integer countUser();
}

